<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let arr1 = [3,6,9,12,13,1,4,7]
        function quickSort(arr){
            if(arr.length <= 1) return arr
            let index = Math.floor(arr.length/2)
            let value = arr.splice(index,1)[0] //splice(index,1)为截取一位值
            let left = []
            let right = []
            arr.forEach((item)=>{
                if(item<value){
                    left.push(item)
                    return
                }
                right.push(item)
            })
            const newLeft = quickSort(left)
            const newRight = quickSort(right)
            return newLeft.concat([value],newRight)
        }
        console.log(quickSort(arr1))
    </script>
</body>
</html>